package Day24;

import java.util.ArrayList;
import java.util.Scanner;

public class View {
    private Scanner sc = new Scanner(System.in);

    //身份
    public int xxx() {
        System.out.println("请输入您的身份：1-管理员  2-用户  0-退出");
        String s = sc.nextLine();
        int a = -1;
        try {
            a = Integer.parseInt(s);
        } catch (NumberFormatException e) {
            System.out.println("输入有误,请重新输入");
            xxx();
        }
        if (a < 0 || a > 2) {
            System.out.println("输入有误，请重新输入");
            xxx();
        }
        return a;
    }

    //管理员操作界面
    public int courier() {
        System.out.println("请输入您需要的操作 1-快递录入  2-删除快递  3-修改快递  4-查看所有快递  0-退出");
        String s = sc.nextLine();
        int a = -1;
        try {
            a = Integer.parseInt(s);
        } catch (NumberFormatException e) {
            System.out.println("输入有误，请重新输入");
            courier();
        }
        if (a < 0 || a > 4) {
            System.out.println("输入有误，请重新输入");
            courier();
        }
        return a;
    }

    //快递录入
    public Express add() {
        Express e = new Express();
        System.out.println("请输入快递单号");
        String s = sc.nextLine();
        System.out.println("请输入快递公司");
        String c = sc.nextLine();
        e.setNumber(s);
        e.setCompany(c);
        return e;
    }

    //快递删除
    public String delete() {
        System.out.println("请输入您要删除的快递编号：");
        String s = sc.nextLine();
        return s;
    }

    //快递修改
    public Express revise() {
        Express e = new Express();
        System.out.println("请输入新的快递编号");
        String s = sc.nextLine();
        System.out.println("请输入新的快递公司:");
        String c = sc.nextLine();
        e.setNumber(s);
        e.setCompany(c);
        return e;
    }

    //快递查找
    public String findNumber(){
        System.out.println("请输入快递编号");
        String s = sc.nextLine();
        return s;
    }

    //遍历快递
    public void printfAll(ArrayList<Express> list){
        if(list.size() == 0){
            System.out.println("暂无快递信息");
        }
        for (Express e:list) {
            printExpress(e);
        }
    }

    //取快递
    public int user(){
        System.out.println("请输入取件码：");
        String s = sc.nextLine();
        int a = -1;
        try {
            a = Integer.parseInt(s);
        }catch (NumberFormatException e){
            System.out.println("输入有误，请重试");
            return user();
        }
        if(a<100000 || a>999999){
            System.out.println("输入不合法");
            return user();
        }
        return a;
    }

    //显示快递信息
    public void printExpress(Express e){
        if(e == null){
            System.out.println("快递信息不存在");
            return;
        }
        System.out.println("快递信息如下");
        System.out.println("快递公司：" + e.getCompany() + " 快递单号" + e.getNumber() + " 快递柜" + e.getGui() + " 取件码：" + e.getCode());
    }
    //打印取件码
    public void printCode(Express e){
        System.out.println("该快递取件码为： " + e.getCode());
    }

    //成功
    public void success(){
        System.out.println("成功");
    }

    //失败
    public void fail(){
        System.out.println("失败");
    }
}
